package Homework10;

public class Doctor {
    private String name;
    private int age;
    private String job;
    private char gender;
    private double sal;

    public Doctor(String name, int age, String job, char gender, double sal) {
        this.name = name;
        this.age = age;
        this.job = job;
        this.gender = gender;
        this.sal = sal;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    //重写父类的equals方法,判断两对象的属性是否相同
    //1.看实参对象是否为Doctor类或其子类
    //2.是->向下转型  否->返回false
    //3.向下转型后一个一个比较属性是否相等
    public boolean equals(Object obj){
        if(this == obj){//先判断两个对象是否为同一个
            return true;
        }
        if(!(obj instanceof Doctor)){
            return false;
        }
       Doctor doctor = (Doctor)obj;
        if(doctor.name.equals(this.name) && doctor.age == this.age && doctor.job.equals(this.job)
                && doctor.sal == this.sal && doctor.gender == this.gender){
            return true;
        }else{
            return false;
        }
    }
}
